require(['grid', 'topBar', 'layout','date'], function () {
	 var postData;
    $('#top').topBar({
        left: [
               {
                   type: 'filter-more',
                   dateType:'custom',
                   search: function () {
                	   search();
                   },
                   item: [
                       {
                           text: '时间快捷',
                           name1: 'beginTime',
                           name2: 'endTime',
                           type: 'dateLine'
                       }, {
                           text: '停车场',
                           name: 'parkingLotCd',
                           type: 'item-select',
                           url : "/sysParking/getParkingInfoListByOrgId.htm",
                           key:'parkingLotCd',
                           value:'parkingLotName',
                           data: [
                               {text: '全部', value: 'All'}
                           ]
                       }
                   ]
               }
        ],
        right: [
            {
                text: '导出',
                type: 'export-btn',
                authority: '',
                item: [
                    {
                        text: 'Excel导出',
                        click: function () {
                        	exportFile('Excel');
                        }
                    },
                    {
                        text: 'PDF导出',
                        click: function () {
                        	exportFile('Pdf');
                        }
                    }
                ]
            }
        ]
    });    

    $('body').layout();
    
    function exportFile(suffix){
		if($('#grid').getGridParam("reccount")>0){
			if(getPostData()){
	    		var url = "/sysParking/exportCarInoutParkingInfo"+suffix+".htm";
				$.exportFile(url,postData);
			}
		}
		else{
			$.messager.alert("警告","请先查询数据！","info");
		}
    }

    $('#grid').grid({
    	url : "/sysParking/searchCarInoutParkingInfoPage.htm",
		multiselect:false,
		colModel:[
		    {name: "parkingLotName", label:"停车场名称", width:"120"},
			{name: "lineName", label:"运营线路", width:"120"},
			{name: "licPltNo", label:"车牌号", width:"120"},
			{name: "inoutType", label:"出入场", width:"100"},
			{name: "inoutTime", label:"出入场时间", width:"120"}]		
    });
    
  //获取左侧选择的节点信息
    function getPostData(){
        postData=$("#top").parent().getValues();
        var type = commonFun.getLeftTreeCurrentTreeType();
        var orgIds = commonFun.getLeftTreeCheckedNodes(type);
        if(!orgIds||orgIds.length<1){
            $.messager.alert("提示","请选择查询车辆/机构/驾驶员。","info");
            return false;
        }
        postData.type = type;
        postData.orgIds =orgIds;
        return true;
    }
    
    function search(){
 	  if(getPostData()){
 	       $('#grid').grid('setGridParam', {
 	    	   page:1,
 	           datatype: "json",
 	           postData: postData
 	       }).trigger("reloadGrid");
 	  }
    }
    
})
